package com.Aug.dao;

import com.Aug.entity.Dept;
import com.Aug.entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DeptDao extends BaseDao{

    public List<Dept> getAllDept() {

        String sql = "select id,name from dept";
        PreparedStatement stat = null;
        Connection conn = getConn();
        ResultSet resultSet = null;
        List<Dept> depts = new ArrayList<>();
        try {
            stat = conn.prepareStatement(sql);
            resultSet = stat.executeQuery();

            while (resultSet.next()){
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");

                Dept dept= new Dept(id, name);
                depts.add(dept);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            closeAll(conn,stat,resultSet);
        }
        return depts;
    }
}
